home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 2: CDPD 1 / Almathera Ten on Ten - Disc 2: CDPD 1.iso / pd / 076-100 / 079 / sharedlib / protect.i < prev    next >
Text File  |  1995-03-13  |  1KB  |  55 lines

  1. ;; Protect.i    Copyright 1987 by James M Synge
  2. ;;
  3. ;; An assembly macro for protecting registers.
  4. ;; Not for the weak of heart.
  5.  
  6.     macro    protect
  7.  
  8.     if    NARG <> 2
  9.     fail        ; Must specify the number of args!
  10.     mexit
  11.     endc
  12.  
  13.     iflt    \2
  14.     fail        ; Negative number of args!
  15.     mexit
  16.     endc
  17.  
  18. ; Until a bug fix arrives for the assembler so that the \0
  19. ; macro works, we must assume the argument size is 4 bytes.
  20.  
  21. \@elementsize    set 4
  22. \@bytes        set \@elementsize * \2
  23. \@offset    set \@bytes + (AztecBugSize * 4)
  24.  
  25.     movem.l    AztecBugList,-(sp)    ; Save some regs
  26.  
  27.     ; Push the argument(s).  We'll use D0 as our scratch
  28.     ; register.  It is free for that use according to
  29.     ; the register convention.  It is used as the result
  30.     ; register.
  31.     
  32.     ifne    \2    ; If there are any arguments
  33.  
  34.     moveq    #\2,d0    ; Number of arguments to move
  35. \@loop    move.l    \@offset(sp),-(sp)    ; Push an arg
  36.     subq.l    #1,d0        ; Last argument?
  37.     bne    \@loop        ; If so, loop again?
  38.  
  39.     endc
  40.  
  41.     jsr    \1    ; Call the C routine
  42.  
  43.     ifne    \2        ; Pop any arguments
  44.     ifge    8 - \@bytes    ; Can we use addq.l?
  45.     addq.l    #\@bytes,sp    ; Yup!
  46.     else
  47.     lea    \@bytes(sp),sp    ; Otherwise use lea
  48.     endc
  49.     endc
  50.  
  51.     movem.l    (sp)+,AztecBugList    ; Restore regs
  52.     rts        ; And return
  53.  
  54.     endm    ; End of the protect macro
  55.